package cc.ryanc.halo.utils;

import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.core.env.Environment;


import javax.servlet.http.HttpServletRequest;


/**
 * 针对数据源配置的公共方法
 */
public class ScAuthUtil {
    private static Logger logger = LoggerFactory.getLogger(ScAuthUtil.class);

    /**
     * 过滤器 判断是否是来自swagger的请求
     */
    public static boolean isSwagger(HttpServletRequest request, Environment environment) {
//        String profile = environment.getProperty("spring.profiles.active", "");
        String requestRefer = request.getHeader("referer");
        boolean fromSwagger = (StringUtils.isNotBlank(requestRefer) && requestRefer.contains("swagger-ui.html"));
        if (!fromSwagger) return false;
//        if ("pro".equals(profile)) {
//            logger.warn("生产环境不允许使用swagger");
//            return false;
//        }
        return true;
    }

}

